package apis

import (
	"context"
	"github.com/kataras/iris/v12"
	"github.com/patrickmn/go-cache"
	"github.com/spf13/pflag"
	"github.com/spf13/viper"
	db2 "gluenet/internal/glue-datasyncer/db"
	"gluenet/pkg/log/v1"
	"gluenet/pkg/nets"
	"gluenet/pkg/ops/dbi"
)

type Label string
type FuncOption func(plugin GlueRunner)
type Handler func(ctx *GlueContext)

type GlueRunner interface {
	InitFlag(flags *pflag.FlagSet)
	ViperConfig(viper *viper.Viper)
	InitViper(viper *viper.Viper)
	Config(opts ...FuncOption)
	Initialize(logger v1.Logger, ctx *GlueContext)
	Close() error
}

type GlueValidator interface {
	Struct(data string, mode, configKind string) error
	Label(label, configKind, mode, kind string) error
	Name(name, configKind, mode, kind string) error
}

type GlueContext struct {
	//Env map[string]string

	Context    context.Context
	RpcContext *nets.NetContext
	WebContext iris.Context

	Validate GlueValidator
	Logger   v1.Logger
	Web      *iris.Application
	Rpc      nets.GlueNets

	Report *cache.Cache
	//DataCache *cache.Cache
	DataBase dbi.GlueDB

	DB *db2.DB
}
